import { Define, EntityObjectFactory } from 'tiny-entity2';
import { OrganizationTree } from './organizationTree';
import { Account } from './account';
import { Role } from './role';

const EntityObjectType = EntityObjectFactory.GetEntityObjectType(process.env.dataBaseType || 'mysql');
@Define.Table({ TableName: "user" })
export class User extends EntityObjectType<User>{
    @Define.PrimaryKey()
    id: string;

    /**
     * 工号
     *
     * @type {string}
     * @memberof User
     */
    @Define.Column({
        DataType: Define.DataType.VARCHAR,
    })
    employeeNo: string;

    /**
     * 单位id
     *
     * @type {string}
     * @memberof User
     */
    @Define.Column({
        DataType: Define.DataType.VARCHAR,
        NotAllowNULL: true
    })
    organizationId: string;


    /**
     * 账号Id
     *
     * @type {string}
     * @memberof User
     */
    @Define.Column({
        DataType: Define.DataType.VARCHAR
    })
    accountId: string;

    /**
     * 姓名
     *
     * @type {string}
     * @memberof User
     */
    @Define.Column({
        DataType: Define.DataType.VARCHAR,
        NotAllowNULL: true
    })
    name: string;

    /**
     * 性别
     *
     * @type {string}
     * @memberof User
     */
    @Define.Column({
        DataType: Define.DataType.VARCHAR,
    })
    gender: string;

    /**
     * 创建时间
     *
     * @type {number}
     * @memberof User
     */
    @Define.Column({
        DataType: Define.DataType.BIGINT,
        NotAllowNULL: true
    })
    createTime: number;

    /**
     * 电话
     *
     * @type {string}
     * @memberof User
     */
    @Define.Column({
        DataType: Define.DataType.VARCHAR
    })
    phone: string;

    /**
     * 出生日期
     *
     * @type {number}
     * @memberof User
     */
    @Define.Column({
        DataType: Define.DataType.BIGINT
    })
    birth: number;

    /**
     * 状态
     *
     * @type {string}
     * @memberof User
     */
    @Define.Column({
        DataType: Define.DataType.VARCHAR
    })
    status: string;

    /**
     * 职位
     *
     * @type {string}
     * @memberof User
     */
    @Define.Column({
        DataType: Define.DataType.VARCHAR
    })
    position: string;

    /**
     * 
     *
     * @type {boolean}
     * @memberof User
     */
    @Define.Column({
        DataType: Define.DataType.BOOL
    })
    isDelete: boolean;

    /**
     * 头像
     *
     * @type {string}
     * @memberof User
     */
    @Define.Column({
        DataType: Define.DataType.VARCHAR
    })
    headerPhoto: string;

    /**
     * 身份号
     *
     * @type {string}
     * @memberof User
     */
    @Define.Column({
        DataType: Define.DataType.VARCHAR
    })
    idCard: string;

    /**
     * 电子邮箱
     *
     * @type {string}
     * @memberof User
     */
    @Define.Column({
        DataType: Define.DataType.VARCHAR
    })
    email: string;

    @Define.Column({
        DataType: Define.DataType.VARCHAR
    })
    level: string;

    /**
     * 座机号码
     *
     * @type {string}
     * @memberof User
     */
    @Define.Column({
        DataType: Define.DataType.VARCHAR
    })
    telephone: string;

    /**
     * 人员相关图片 ['urlpath']
     *
     * @type {*}
     * @memberof User
     */
    @Define.Column({
        DataType: Define.DataType.JSON
    })
    imageList: UserImage[];

    /**
     * 人员扩展
     *
     * @type {*}
     * @memberof User
     */
    @Define.Column({
        DataType: Define.DataType.JSON
    })
    extends: EmployeeExtends;

    @Define.Mapping({
        Mapping: 'OrganizationTree',
        MappingKey: { FKey: 'objectId', MKey: 'id' },
        MappingType: Define.MappingType.One
    })
    orgTree: OrganizationTree;

    /**
     * 部门信息
     *
     * @type {Department}
     * @memberof User
     */
    departmentNode: OrganizationTree;

    @Define.Column({
        DataType: Define.DataType.VARCHAR
    })
    userType: string;

    @Define.Mapping({
        Mapping: 'Account',
        MappingKey: { FKey: 'id', MKey: 'accountId' },
        MappingType: Define.MappingType.One
    })
    acc: Account;

    roles: Role[];
}

export const EmployeeStatus = {
    Disable: 'disable'
}

export const UserType = {
    Normal: 'normal',
    Admin: 'admin'
}

interface EmployeeExtends {
    /**
     * 入职时间
     *
     * @type {number}
     * @memberof EmployeeExtends
     */
    entryTime: number;
    /**
     * 转正时间
     *
     * @type {number}
     * @memberof EmployeeExtends
     */
    regularTime: number;
    /**
     * 合同到期时间
     *
     * @type {number}
     * @memberof EmployeeExtends
     */
    contractEndTime: number;

    /**
     * 岗位级别
     *
     * @type {string}
     * @memberof EmployeeExtends
     */
    positionLevel: string;
}

interface UserImage {
    id: string;
    /**
     * 文件名称
     *
     * @type {string}
     * @memberof UserImage
     */
    name: string;
    /**
     * 图片地址
     *
     * @type {string}
     * @memberof UserImage
     */
    /**
     *
     *
     * @type {string}
     * @memberof UserImage
     */
    url: string;
}